/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package factory;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import Model.User;

/**
 *
 * @author Admin
 */
public class DataHandling {

    public static ArrayList<User> loadData() {
        ArrayList<User> userList;
        try {
            FileInputStream fis = new FileInputStream(Constants.FILE_SAVE);
            ObjectInputStream ois = new ObjectInputStream(fis);
            userList = (ArrayList<User>) ois.readObject();
            return userList;
        } catch (Exception ex) {
            return new ArrayList<User>();
        }
    }

    public static void saveData(ArrayList<User> userList) {
        try {
            FileOutputStream fos = new FileOutputStream(Constants.FILE_SAVE);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(userList);
        } catch (Exception ex) {
//            System.out.println(ex.toString());
        }
    }
}
